package com.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.world.World;

public class MenuScreen implements Screen {
	
	private Start game;					// Das Spielframe
	
	private TextureAtlas atlas;
	private Skin skin;
	private Stage stage;
	
	public MenuScreen(Start game) {		
		this.game = game;
  
		stage = new Stage();

        Gdx.input.setInputProcessor(stage);

        atlas = new TextureAtlas(Gdx.files.internal("img/misc/menu/buttons.pack"));
        skin = new Skin();
        skin.addRegions(atlas);         

        ButtonStyle startStyle = new ButtonStyle();
        startStyle.up = skin.getDrawable("start");
        startStyle.over = skin.getDrawable("startHover");
        
        ButtonStyle quitStyle = new ButtonStyle();
        quitStyle.up = skin.getDrawable("quit");
        quitStyle.over = skin.getDrawable("quitHover");
        
        Button startButton = new Button(startStyle);
        startButton.setX(World.WIDTH / 2 - startButton.getWidth() / 2);
        startButton.setY(World.HEIGHT / 2 - startButton.getHeight() / 2 + 30);
        startButton.addListener(new InputListener() {
            public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
            	startChoose();
                return true;
            }
        });
        
        Button quitButton = new Button(quitStyle);
        quitButton.setX(World.WIDTH / 2 - quitButton.getWidth() / 2);
        quitButton.setY(World.HEIGHT / 2 - quitButton.getHeight() / 2 - 30);
        quitButton.addListener(new InputListener() {
            public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
            	dispose();
            	Gdx.app.exit();
                return true;
            }
        });
        
        stage.addActor(startButton);
        stage.addActor(quitButton);
	}

	@Override
	public void render(float delta) {		
		Gdx.gl.glClearColor(0, 0, 0, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		
		stage.act(Gdx.graphics.getDeltaTime());
        stage.draw();
	}

	@Override
	public void resize(int width, int height) {
	}

	@Override
	public void show() {
	}

	@Override
	public void hide() {
	}

	@Override
	public void pause() {
	}

	@Override
	public void resume() {
	}

	@Override
	public void dispose() {
		atlas.dispose();
		stage.dispose();
		skin.dispose();
	}
	
	public void startChoose() {
		game.setScreen(new ChooseHeroScreen(game));
        dispose();
	}
}
